﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using YYTea.MOdel.Model;
using YYTea.ORM;
using YYTea.Services.IServices;
using YYTea.Services.VModel;

namespace YYTea.Miljy.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class OrderController : ControllerBase
    {
        private readonly IOrder _order;
        public OrderController(IOrder order)
        {
            this._order = order;
        }

        [HttpPost]
        public async Task<IActionResult> AddressAddOrUpdate(Guid shoppingCarId, OrderAddressCRUD addRess)
        {
            if (shoppingCarId == null)
            {
                return BadRequest("找不到该用户购物车");
            }
            //if (addRess == null)
            //{
            //    return BadRequest("请输入地址");
            //}
            var addre = await _order.AddAddress(addRess, shoppingCarId);
            return Ok(addre);
        }


        [HttpPost]
        public async Task<IActionResult> AddressDelete(Guid shoppingCarId)
        {
            if (shoppingCarId == null)
            {
                return BadRequest("找不到该用户购物车");
            }
            var deleteOrder = await _order.DeleteAddress(shoppingCarId);
            return Ok(deleteOrder);
        }
    }
}
